#include <cstdio>

int a1[ 8 ], b1[ 8 ], a2[ 4 ][ 4 ], b2[ 4 ][ 4 ];

void init( )
{
    int i, j;
    scanf("%d%d%d", &a1[ 0 ], &a1[ 1 ], &a1[ 2 ]);
    for ( i = 0; i < 4; i++ ) scanf("%d", &a2[ 0 ][ i ]);
    scanf("%d", &a1[ 3 ]);
    for ( i = 1; i <= 2; i++ )
        for ( j = 0; j < 4; j++ )
            scanf("%d", &a2[ i ][ j ]);
    scanf("%d", &a1[ 4 ]);
    for ( i = 0; i < 4; i++ ) scanf("%d", &a2[ 3 ][ i ]);
    scanf("%d%d%d", &a1[ 5 ], &a1[ 6 ], &a1[ 7 ]);
    scanf("%d%d%d", &b1[ 0 ], &b1[ 1 ], &b1[ 2 ]);
    for ( i = 0; i < 4; i++ ) scanf("%d", &b2[ 0 ][ i ]);
    scanf("%d", &b1[ 3 ]);
    for ( i = 1; i <= 2; i++ )
        for ( j = 0; j < 4; j++ )
            scanf("%d", &b2[ i ][ j ]);
    scanf("%d", &b1[ 4 ]);
    for ( i = 0; i < 4; i++ ) scanf("%d", &b2[ 3 ][ i ]);
    scanf("%d%d%d", &b1[ 5 ], &b1[ 6 ], &b1[ 7 ]);

}

int mabs( int x ) { return ( x < 0 ) ?-x :x; }

int hdistance( int a[][ 4 ], int b[][ 4 ] )
{
    int i, j, ret1 = 0, ret2 = 0, tx, ty, t;
    for ( i = 0; i < 4; i++ )
        for ( j = 0; j < 4; j++ )
            if ( a[ i ][ j ] == 0 )
            {
                tx = i; ty = j;
                break;
            }
    for ( i = tx + 1; i < 4; i++ )
        a[ i - 1 ][ ty ] = a[ i ][ ty ];
    for ( i = ty + 1; i < 4; i++ )
        a[ 3 ][ i - 1 ] = a[ 3 ][ i ];
    a[ 3 ][ 3 ] = 0;
    for ( i = 0; i < 4; i++ )
        for ( j = 0; j < 4; j++ )
            if ( b[ i ][ j ] == 0 )
            {
                tx = i; ty = j;
                break;
            }
    for ( i = tx + 1; i < 4; i++ )
        b[ i - 1 ][ ty ] = b[ i ][ ty ];
    for ( i = ty + 1; i < 4; i++ )
        b[ 3 ][ i - 1 ] = b[ 3 ][ i ];
    b[ 3 ][ 3 ] = 0;
    for ( i = 0; i < 15; i++ )
        for ( j = 0; j < i; j++ )
        {
            if ( a[ j / 4 ][ j % 4 ] > a[ i / 4 ][ i % 4 ] )
                ret1++;
            if ( b[ j / 4 ][ j % 4 ] > b[ i / 4 ][ i % 4 ] )
                ret2++;
        }
    return ret1 + ret2;
}

void work( )
{
    int i, j, t1 = -1, t2 = -1;
    for ( i = 0; i < 8; i++ )
    {
        if ( a1[ i ] != b1[ i ] && a1[ i ] && b1[ i ] )
            break;
        if ( !a1[ i ] ) t1 = i;
        if ( !b1[ i ] ) t2 = i;
    }
    if ( i < 8 )
    {
        puts("Y");
        return ;
    }
    if ( t1 == -1 && t2 == -1 )
    {
        if ( hdistance( a2, b2 ) % 2 )
            puts("Y");
        else
            puts("N");
        return ;
    }
    if ( t1 == -1 )
    {
        switch( t2 )
        {
            case 0: case 2:
                if ( a1[ t2 ] != b2[ 0 ][ 0 ] ) { puts("Y"); return ; }
                b2[ 0 ][ 0 ] = 0; if ( hdistance( a2, b2 ) % 2 ) puts("Y"); else puts("N"); return ;
                break;
            case 1: case 3:
                if ( a1[ t2 ] != b2[ 0 ][ 3 ] ) { puts("Y"); return ; }
                b2[ 0 ][ 3 ] = 0; if ( hdistance( a2, b2 ) % 2 ) puts("Y"); else puts("N"); return ;
                break;
            case 4: case 6:
                if ( a1[ t2 ] != b2[ 3 ][ 0 ] ) { puts("Y"); return ; }
                b2[ 3 ][ 0 ] = 0; if ( hdistance( a2, b2 ) % 2 ) puts("Y"); else puts("N"); return ;
                break;
            case 5: case 7:
                if ( a1[ t2 ] != b2[ 3 ][ 3 ] ) { puts("Y"); return ; }
                b2[ 3 ][ 3 ] = 0; if ( hdistance( a2, b2 ) % 2 ) puts("Y"); else puts("N"); return ;
                break;
        }
    }
    if ( t2 == -1 )
    {
        switch( t1 )
        {
            case 0: case 2:
                if ( b1[ t1 ] != a2[ 0 ][ 0 ] ) { puts("Y"); return ; }
                a2[ 0 ][ 0 ] = 0; if ( hdistance( a2, b2 ) % 2 ) puts("Y"); else puts("N"); return ;
                break;
            case 1: case 3:
                if ( b1[ t1 ] != a2[ 0 ][ 3 ] ) { puts("Y"); return ; }
                a2[ 0 ][ 3 ] = 0; if ( hdistance( a2, b2 ) % 2 ) puts("Y"); else puts("N"); return ;
                break;
            case 4: case 6:
                if ( b1[ t1 ] != a2[ 3 ][ 0 ] ) { puts("Y"); return ; }
                a2[ 3 ][ 0 ] = 0; if ( hdistance( a2, b2 ) % 2 ) puts("Y"); else puts("N"); return ;
                break;
            case 5: case 7:
                if ( b1[ t1 ] != a2[ 3 ][ 3 ] ) { puts("Y"); return ; }
                a2[ 3 ][ 3 ] = 0; if ( hdistance( a2, b2 ) % 2 ) puts("Y"); else puts("N"); return ;
                break;
        }
    }
    if ( t1 != t2 )
    {
        switch( t1 )
        {
            case 0: case 2:
                if ( b1[ t1 ] != a2[ 0 ][ 0 ] ) { puts("Y"); return ; }
                a2[ 0 ][ 0 ] = 0;
                break;
            case 1: case 3:
                if ( b1[ t1 ] != a2[ 0 ][ 3 ] ) { puts("Y"); return ; }
                a2[ 0 ][ 3 ] = 0;
                break;
            case 4: case 6:
                if ( b1[ t1 ] != a2[ 3 ][ 0 ] ) { puts("Y"); return ; }
                a2[ 3 ][ 0 ] = 0;
                break;
            case 5: case 7:
                if ( b1[ t1 ] != a2[ 3 ][ 3 ] ) { puts("Y"); return ; }
                a2[ 3 ][ 3 ] = 0;
                break;
        }
        switch( t2 )
        {
            case 0: case 2:
                if ( a1[ t2 ] != b2[ 0 ][ 0 ] ) { puts("Y"); return ; }
                b2[ 0 ][ 0 ] = 0;
                break;
            case 1: case 3:
                if ( a1[ t2 ] != b2[ 0 ][ 3 ] ) { puts("Y"); return ; }
                b2[ 0 ][ 3 ] = 0;
                break;
            case 4: case 6:
                if ( a1[ t2 ] != b2[ 3 ][ 0 ] ) { puts("Y"); return ; }
                b2[ 3 ][ 0 ] = 0;
                break;
            case 5: case 7:
                if ( a1[ t2 ] != b2[ 3 ][ 3 ] ) { puts("Y"); return ; }
                b2[ 3 ][ 3 ] = 0;
                break;
        }
    /*    for ( i = 0; i < 4; i++ )
        {
            for ( j = 0; j < 4; j++ ) printf("%d ", a2[ i ][ j ] );
            printf("\n");
        }
        printf("\n");
        for ( i = 0; i < 4; i++ )
        {
            for ( j = 0; j < 4; j++ ) printf("%d ", b2[ i ][ j ] );
            printf("\n");
        }
        printf("\n");*/
        if ( hdistance( a2, b2 ) % 2 )
            puts("Y");
        else
            puts("N");
    }
    else
    {
        switch( t1 )
        {
            case 0: case 2:
                if ( b2[ 0 ][ 0 ] != a2[ 0 ][ 0 ] ) { puts("Y"); return ; }
                a2[ 0 ][ 0 ] = b2[ 0 ][ 0 ] = 0;
                break;
            case 1: case 3:
                if ( b2[ 0 ][ 3 ] != a2[ 0 ][ 3 ] ) { puts("Y"); return ; }
                a2[ 0 ][ 3 ] = b2[ 0 ][ 3 ] = 0;
                break;
            case 4: case 6:
                if ( b2[ 3 ][ 0 ] != a2[ 3 ][ 0 ] ) { puts("Y"); return ; }
                a2[ 3 ][ 0 ] = b2[ 3 ][ 0 ] = 0;
                break;
            case 5: case 7:
                if ( b2[ 3 ][ 3 ] != a2[ 3 ][ 3 ] ) { puts("Y"); return ; }
                a2[ 3 ][ 3 ] = b2[ 3 ][ 3 ] = 0;
                break;
        }
        if ( hdistance( a2, b2 ) % 2 )
            puts("Y");
        else
            puts("N");
    }
}

int main( )
{
    int t;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        work( );
    }
    return 0;
}
